﻿
Namespace UI.Controls
	Public Class WindowSystemButtons

		Public Property WindowState As WindowState
			Get
				Return GetValue(WindowStateProperty)
			End Get

			Set(ByVal value As WindowState)
				SetValue(WindowStateProperty, value)
			End Set
		End Property

		Public Shared ReadOnly WindowStateProperty As DependencyProperty = _
							   DependencyProperty.Register("WindowState", _
							   GetType(WindowState), GetType(WindowSystemButtons), _
							   New PropertyMetadata(WindowState.Normal))


		Public Property ResizeMode As ResizeMode
			Get
				Return GetValue(ResizeModeProperty)
			End Get

			Set(ByVal value As ResizeMode)
				SetValue(ResizeModeProperty, value)

			End Set
		End Property

		Public Shared ReadOnly ResizeModeProperty As DependencyProperty = _
							   DependencyProperty.Register("ResizeMode", _
							   GetType(ResizeMode), GetType(WindowSystemButtons), _
							   New PropertyMetadata(System.Windows.ResizeMode.CanResize, New PropertyChangedCallback(AddressOf ResizeModeUpdated)))

		Public Shared Sub ResizeModeUpdated(sender As Object, e As DependencyPropertyChangedEventArgs)
			CType(sender, WindowSystemButtons).ResizeModeUpdate(sender, e)
		End Sub

		Public Sub ResizeModeUpdate(sender As Object, e As DependencyPropertyChangedEventArgs)
			If e.NewValue = System.Windows.ResizeMode.NoResize Then
				Minimize.Visibility = System.Windows.Visibility.Collapsed
				MaxRestoreButtons.Visibility = System.Windows.Visibility.Collapsed
			ElseIf e.NewValue = System.Windows.ResizeMode.CanMinimize Then
				Minimize.Visibility = System.Windows.Visibility.Visible
				MaxRestoreButtons.Visibility = System.Windows.Visibility.Collapsed
			ElseIf e.NewValue = System.Windows.ResizeMode.CanResize OrElse e.NewValue = System.Windows.ResizeMode.CanResizeWithGrip Then
				Minimize.Visibility = System.Windows.Visibility.Visible
				MaxRestoreButtons.Visibility = System.Windows.Visibility.Visible
			End If
		End Sub


		Private Sub MinimizeClick(sender As Object, e As RoutedEventArgs)
			WindowState = System.Windows.WindowState.Minimized
		End Sub

		Private Sub MaximizeClick(sender As Object, e As RoutedEventArgs)
			WindowState = System.Windows.WindowState.Maximized
		End Sub

		Private Sub RestoreClick(sender As Object, e As RoutedEventArgs)
			WindowState = System.Windows.WindowState.Normal
		End Sub

		Private Sub CloseClick(sender As Object, e As RoutedEventArgs)
			Window.GetWindow(Me).Close()
		End Sub





	End Class
End Namespace